package utils;

public class UrlUtils {

    private static final String URL_SPLIT = "/";

    public static void main(String[] args) {
        String sUrl = "a/b//c/////////";
        String cUrl = "/a//b/c";
        System.out.println(compare(sUrl,cUrl));
    }


    public static boolean compare(String sUrl,String cUrl){
        if(!StringUtils.isNullOrEmpty(sUrl)){
            String[] checkUrlArr = cUrl.split(URL_SPLIT);
            String[] sourceUrlArr = sUrl.split(URL_SPLIT);
            int cIdx = 0,sIdx= 0;
            while (cIdx < checkUrlArr.length && sIdx < sourceUrlArr.length) {
                if (StringUtils.isNullOrEmpty(checkUrlArr[cIdx])) {
                    cIdx++;
                } else if (StringUtils.isNullOrEmpty(sourceUrlArr[sIdx])) {
                    sIdx++;
                } else if (sourceUrlArr[sIdx].equalsIgnoreCase(checkUrlArr[cIdx])) {
                    cIdx++;
                    sIdx++;
                } else {
                    return false;
                }
            }

            while (cIdx < checkUrlArr.length && StringUtils.isNullOrEmpty(checkUrlArr[cIdx])){
                cIdx ++;
            }

            while (sIdx < sourceUrlArr.length && StringUtils.isNullOrEmpty(sourceUrlArr[sIdx])){
                sIdx ++;
            }
            if(cIdx < checkUrlArr.length || sIdx < sourceUrlArr.length){
                return false;
            }
        }
        return true;
    }
}
